﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wicresoft.EKA.NRemedy;

namespace Wicresoft.EKA.NRemedy.ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string ARServer = ConfigurationManager.AppSettings["ARServer"];
            string ARUid = ConfigurationManager.AppSettings["ARUid"];
            string ARPwd = ConfigurationManager.AppSettings["ARPwd"];
            GlobalSettings.SetCharacterEncoding("UTF8");    //GlobalSetting 里面 
            ARLoginContext context = new ARLoginContext(ARServer, ARUid, ARPwd);
            ARProxy<TestModel> ar = new ARProxy<TestModel>(context);


            DateTime startTime = DateTime.Now;
            TestModel test = new TestModel();

            context.BeginBulkEntryTransaction();
            for (int i = 0; i < 2000; i++)
            {
                test = new TestModel()
                {
                    Submitter = "Demo",
                    ShortDescription = i.ToString(),
                    CharacterField = "Char",
                    CheckBoxField = TestModel.CheckBoxField_Enum.Default1,
                    DateField = new BMC.ARSystem.DateValue(DateTime.Now),
                    DecimalNumberField = 1,
                    DiaryFieldSet = "Diary",
                    DropDownListField = TestModel.DropDownListField_Enum.Default1,
                    IntegerField = 1,
                    RadioButtonField = TestModel.RadioButtonField_Enum.Default1,
                    RealNumberField = 1.0,
                    TimeField = new BMC.ARSystem.TimeOfDayValue(1, 2, 3)
                };
                ar.CreateEntry(test);
            }
            context.SendBulkEntryTransaction();

            Console.WriteLine(TestModel.LastModifiedBy_Name);

            Console.WriteLine(startTime.ToString());
            Console.WriteLine(DateTime.Now.ToString());

            //for (int i = 0; i < 2000; i++)
            //{
            //    string querystr = string.Format("\'Short Description\'=\"{0}\"", i.ToString());
            //    TestModel model = ar.GetListEntry(querystr, new List<uint>() { TestModel.RequestID_ID,TestModel.ShortDescription_ID }).FirstOrDefault();
            //    model.ShortDescription += "Hello";
            //    ar.SetEntry(model);
            //    Console.WriteLine(i);
            //}


            //for (int i = 0; i < 2000; i++)
            //{
            //    string querystr = string.Format("\'Short Description\'=\"{0}\"", i.ToString());
            //    ar.DeleteEntryByQuery(querystr);
            //    Console.WriteLine(i);
            //}

            //string requestID = "000000000000001";
            //string querystr = string.Format("\'Request ID\'=\"{0}\"", requestID);

            //for (int i = 0; i < 1000000; i++)
            //{
            //    UserModel u = ar.GetListEntry(querystr).FirstOrDefault();
            //    Console.WriteLine(i);
            //}

            Console.ReadLine();
        }
    }
}
